home *** CD-ROM | disk | FTP | other *** search
- /*
- File: System8Resources.cp
-
- Contains: The System 7 resource manager redefined in
- terms of the System 8 Resource Manager.
- Make this file as a shared library.
-
- Written by: Chris Thomas <ckt@best.com>
- bug reports, suggestions, comments welcome!
-
- Version: 1.0
-
- Copyright: © 1995 Chris K. Thomas. All Rights Reserved.
- © 1995 Apple Computer, Inc. All Rights Reserved.
-
- Change History (most recent first):
-
- 8/23/95 ckt Created.
-
- I decided that I didn't want to litter my resource
- code with dozens of #ifdefs for System 7-8 compatibility,
- and this was so easy!
-
- One thing I find odd about the Copland Res Manager
- is that it supports UInt32 numbers of resources by
- index, but still only SInt16 by id.
-
- These could probably be inlined for C++.
-
- While this appears to work for me, it may not work for you.
- No warranties express or implied, no guaranteed results.
- */
-
- #include "System8Resources.h"
-
- OSStatus RMCloseResFile(ResFileRefNum refNum)
- {
- OSStatus outErr = 0L;
-
- CloseResFile(refNum);
-
- outErr = ResError();
- return outErr;
- }
-
- OSStatus RMUseResFile(ResFileRefNum refNum)
- {
- OSStatus outErr = 0L;
-
- UseResFile(refNum);
-
- outErr = ResError();
- return outErr;
- }
-
- OSStatus RMCurResFile(ResFileRefNum* refNum)
- {
- OSStatus outErr = 0L;
-
- *refNum = CurResFile();
-
- outErr = ResError();
- return outErr;
- }
-
- OSStatus RMHomeResFile(Handle theResource, ResFileRefNum *refNum)
- {
- OSStatus outErr = 0L;
-
- *refNum = HomeResFile(theResource);
-
- outErr = ResError();
- return outErr;
- }
-
- OSStatus RMAddResource(Handle theData, ResType theType, ResID theID, ConstStr255Param name)
- {
- OSStatus outErr = 0L;
-
- AddResource(theData, theType, theID, name);
-
- outErr = ResError();
- return outErr;
- }
-
- OSStatus RMRemoveResource(Handle theResource)
- {
- OSStatus outErr = 0L;
-
- RemoveResource(theResource);
-
- outErr = ResError();
- return outErr;
- }
-
- OSStatus RMCountTypes(Boolean oneDeep, UInt32 *count)
- {
- OSStatus outErr = 0L;
-
- if(oneDeep)
- *count = Count1Types();
- else
- *count = CountTypes();
-
- outErr = ResError();
- return outErr;
- }
-
- OSStatus RMGetIndexedType(UInt32 index, Boolean oneDeep, ResType *theType)
- {
- OSStatus outErr = 0L;
-
- if(oneDeep)
- Get1IndType(theType, index);
- else
- GetIndType(theType, index);
-
- outErr = ResError();
- return outErr;
- }
-
- OSStatus RMCountResources(ResType theType, Boolean oneDeep, UInt32 *count)
- {
- OSStatus outErr = 0L;
-
- if(oneDeep)
- *count = Count1Resources(theType);
- else
- *count = CountResources(theType);
-
- outErr = ResError();
- return outErr;
- }
-
- OSStatus RMGetIndexedResource(ResType theType, UInt32 index, Boolean oneDeep, Boolean resLoad, Handle *handle)
- {
- OSStatus outErr = 0L;
- UInt8 saveResLoad;
-
- saveResLoad = LMGetResLoad();
- SetResLoad(resLoad);
-
- if(oneDeep)
- *handle = Get1IndResource(theType, index);
- else
- *handle = GetIndResource(theType, index);
-
- outErr = ResError();
-
- SetResLoad(saveResLoad);
- return outErr;
- }
-
-
- OSStatus RMGetResource(ResType theType, ResID theID, Boolean oneDeep, Boolean resLoad, Handle *handle)
- {
- OSStatus outErr = 0L;
- UInt8 saveResLoad;
-
- saveResLoad = LMGetResLoad();
- SetResLoad(resLoad);
-
- if(oneDeep)
- *handle = Get1Resource(theType, theID);
- else
- *handle = GetResource(theType, theID);
-
- outErr = ResError();
-
- SetResLoad(saveResLoad);
- return outErr;
- }
-
-
- OSStatus RMGetNamedResource(ResType theType, ConstStr255Param name, Boolean oneDeep, Boolean resLoad, Handle *handle)
- {
- OSStatus outErr = 0L;
- UInt8 saveResLoad;
-
- saveResLoad = LMGetResLoad();
- SetResLoad(resLoad);
-
- if(oneDeep)
- *handle = Get1NamedResource(theType, name);
- else
- *handle = GetNamedResource(theType, name);
-
- outErr = ResError();
-
- SetResLoad(saveResLoad);
- return outErr;
- }
-
-
-
- OSStatus RMLoadResource(Handle theResource)
- {
- OSStatus outErr = 0L;
-
- LoadResource(theResource);
-
- outErr = ResError();
- return outErr;
- }
-
-
- OSStatus RMReleaseResource(Handle theResource)
- {
- OSStatus outErr = 0L;
-
- ReleaseResource(theResource);
-
- outErr = ResError();
- return outErr;
- }
-
-
- OSStatus RMDetachResource(Handle theResource)
- {
- OSStatus outErr = 0L;
-
- DetachResource(theResource);
-
- outErr = ResError();
- return outErr;
- }
-
-
-
- OSStatus RMChangedResource(Handle theResource)
- {
- OSStatus outErr = 0L;
-
- ChangedResource(theResource);
-
- outErr = ResError();
- return outErr;
- }
-
-
- OSStatus RMWriteResource(Handle theResource)
- {
- OSStatus outErr = 0L;
-
- WriteResource(theResource);
-
- outErr = ResError();
- return outErr;
- }
-
-
- OSStatus RMSetResourceSize(Handle theResource, SInt32 newSize)
- {
- OSStatus outErr = 0L;
-
- SetResourceSize(theResource, newSize);
-
- outErr = ResError();
- return outErr;
- }
-
-
- OSStatus RMUniqueID(ResType theType, Boolean oneDeep, ResID *idPtr)
- {
- OSStatus outErr = 0L;
-
- if(oneDeep)
- *idPtr = Unique1ID(theType);
- else
- *idPtr = UniqueID(theType);
-
- outErr = ResError();
- return outErr;
- }
-
-
-
- OSStatus RMGetResAttributes(Handle theResource, ResAttributes *attributes)
- {
- OSStatus outErr = 0L;
-
- *attributes = GetResAttrs(theResource);
-
- outErr = ResError();
- return outErr;
- }
-
-
- OSStatus RMGetResInfo(Handle theResource, ResType *typePtr, ResID *idPtr, Str255 name)
- {
- OSStatus outErr = 0L;
-
- GetResInfo(theResource, idPtr, typePtr, name);
-
- outErr = ResError();
- return outErr;
- }
-
-
- OSStatus RMSetResInfo(Handle theResource, ResType, ResID theID, ConstStr255Param name)
- {
- OSStatus outErr = 0L;
-
- SetResInfo(theResource, theID, name);
-
- outErr = ResError();
- return outErr;
- }
-
-
-
- OSStatus RMSetResAttributes(Handle theResource, ResAttributes attrs)
- {
- OSStatus outErr = 0L;
-
- SetResAttrs(theResource, attrs);
-
- outErr = ResError();
- return outErr;
- }
-
-
- OSStatus RMReadPartialResource(Handle theResource, UInt32 offset, void *buffer, UInt32 count)
- {
- OSStatus outErr = 0L;
-
- ReadPartialResource(theResource, (long)offset, buffer, (long)count);
-
- outErr = ResError();
- return outErr;
- }
-
-
- OSStatus RMWritePartialResource(Handle theResource, UInt32 offset, const void *buffer, UInt32 count)
- {
- OSStatus outErr = 0L;
-
- WritePartialResource(theResource, (long) offset, buffer, (long) count);
-
- outErr = ResError();
- return outErr;
- }
-
- /*
- * GetResourceSize returns either the size of the handle if the handle
- * is not empty or the size of the resource as stored on disk (i.e.
- * it has the exact semantics of GetResourceSizeOnDisk but does not
- * have the confusing name).
- */
-
- OSStatus RMGetResourceSize(Handle theResource, SInt32 *size)
- {
- OSStatus outErr = 0L;
-
- *size = GetResourceSizeOnDisk(theResource);
-
- outErr = ResError();
- return outErr;
- }
-
- OSStatus RMSetResErrProc(ResErrUPP proc)
- {
- OSStatus outErr = 0L;
-
- LMSetResErrProc(proc);
-
- return outErr;
- }
-
-
- OSStatus RMSetResFileReadOnlyState(ResFileRefNum refNum, Boolean isReadOnly)
- {
- OSStatus outErr = 0L;
-
- // * should we do a GetResFileAttrs first, or does it matter?
- SetResFileAttrs(refNum, isReadOnly ? mapReadOnly : 0);
-
- outErr = ResError();
- return outErr;
- }
-
-
- OSStatus RMGetResFileReadOnlyState(ResFileRefNum refNum, Boolean *isReadOnly)
- {
- OSStatus outErr = 0L;
- short attrs;
-
- attrs = GetResFileAttrs(refNum);
-
- if(attrs & mapReadOnly)
- *isReadOnly = true;
- else
- *isReadOnly = false;
-
- outErr = ResError();
- return outErr;
- }
-